package com.seeyon.apps.seepkk.form.workflowevent;

import com.seeyon.apps.kk.form.workflowevent.KkBaseExtendPlug;
import com.seeyon.apps.seepkk.manager.SeepManager;
import com.seeyon.cap4.form.bean.FormBean;
import com.seeyon.cap4.form.bean.FormDataMasterBean;
import com.seeyon.cap4.form.bean.FormTableBean;
import com.seeyon.ctp.common.constants.ApplicationCategoryEnum;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.workflow.event.WorkflowEventData;
import com.seeyon.ctp.workflow.event.WorkflowEventResult;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.Map;

public class SeepKkMeetingExtendPlug extends KkBaseExtendPlug {
    @Override
    public String getId() {
        return "seepKkMeetingExtendPlug";
    }

    @Override
    public String getLabel() {
        return "参会者提名科室校验";
    }

    public ApplicationCategoryEnum getAppName() {
        return ApplicationCategoryEnum.form;
    }

    private static final Log log = LogFactory.getLog(SeepKkMeetingExtendPlug.class);
    private SeepManager seepManager;

    public SeepManager getSeepManager() {
        return seepManager;
    }

    public void setSeepManager(SeepManager seepManager) {
        this.seepManager = seepManager;
    }

    // 发起前事件
    public WorkflowEventResult onBeforeStart(WorkflowEventData data) {
        WorkflowEventResult result = new WorkflowEventResult();
        Map<String, Object> formdata = data.getBusinessData();
        FormBean formBean = (FormBean) data.getBusinessData().get("formBean");
        FormDataMasterBean formDataMasterBean = (FormDataMasterBean) data.getBusinessData().get("formDataBean");
        FormTableBean formTableBean = formDataMasterBean.getFormTable();
        log.info("参会者提名发起事件！");
        // 数据校验
        String resultMsg = "";

        resultMsg = this.seepManager.isCheckMeeting(formBean, formdata, formTableBean, formDataMasterBean.getAllDataMap());

        result.setAlertMessage(resultMsg);
        return result;
    }
}
